//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Logging Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

namespace EntLibContrib.Logging.Install
{
	internal class LoggingConfigurationLoader : MarshalByRefObject
	{
		private List<EventLogConfiguration> eventLogs_;

		/// <summary>
		/// Initializes a new instance of the <see cref="LoggingConfigurationLoader"/> class.
		/// </summary>
		public LoggingConfigurationLoader()
		{
			this.eventLogs_ = new List<EventLogConfiguration>();

			IConfigurationSource configSource =
					ConfigurationSourceFactory.Create();
			LoggingSettings loggingConfig =
					(LoggingSettings)configSource.GetSection(
					LoggingSettings.SectionName);
			foreach (TraceListenerData tld in loggingConfig.TraceListeners)
			{
				FormattedEventLogTraceListenerData feltld =
						tld as FormattedEventLogTraceListenerData;
				if (feltld != null)
				{
					EventLogConfiguration elc =
							new EventLogConfiguration(feltld.Log, feltld.Source);
					this.eventLogs_.Add(elc);
				}
			}
		}

		internal IList<EventLogConfiguration> EventLogs
		{
			get { return this.eventLogs_; }
		}
	}
}
